<script setup>
import{selectExamTitleStuService,
    saveExamTitleStuService
} from '@/api/ExamManager.js'
import {ref} from 'vue'
import { useUserStore } from '@/stores/user';
const userStore = useUserStore();

const params = ref({
    teacherId:''
})
const handleClick = () => {
  console.log('click')
}
const ExamTitleStuList = ref([])
const ExamTitleStu = ref({
      id:'',
      examTitle:'',
      examPoint:'',
      studentId:'',
      studentName:'',
      examTitleValue:'',
      teacherPoint:''
})
const selectExamTitleStu = async () => {
    params.value.teacherId = userStore.token
    const res = await selectExamTitleStuService(params.value);
    ExamTitleStuList.value = res.data.data
    ExamTitleStu.value = {}
    dialogVisible.value = false
}
selectExamTitleStu()


const dialogVisible = ref(false)

const editRow = (row) => {
    dialogVisible.value = true
    ExamTitleStu.value = row
}
const confirmPoint = async () => {
    await saveExamTitleStuService(ExamTitleStu.value)
    ElMessage.success('成功！')
    selectExamTitleStu()
    dialogVisible.value = false
}

const search = () => {
    selectExamTitleStu()
}
</script>

<template>
  <div>
    <div class="cus-header">
        <el-card>
            <div class="search">
                
                <div style="margin-left: 20px;">
                    姓名：
                    <el-input v-model="input" style="width: 240px" placeholder="请输入姓名" />
                </div>
                <div style="margin-left: 20px;">
                    <el-button @click="search" style="width: 80px;" type="primary">搜索</el-button>
                </div>
            </div>
        </el-card>
    </div>
    <div class="cus-body">
        <el-card style="min-height: 650px;">
            <el-table :data="ExamTitleStuList" style="width: 100%">
                <el-table-column fixed prop="id" label="编号" width="120" />
                <el-table-column prop="examTitle" label="考试题目" width="150" />
                <el-table-column prop="examPoint" label="题目分数" width="120" />
                <el-table-column prop="studentId" label="学生编号" width="120" />
                <el-table-column prop="studentName" label="学生名称" width="120" />
                <el-table-column prop="examTitleValue" label="学生答案" width="120" />
                <el-table-column prop="teacherPoint" label="老师评分" width="120" />
                <el-table-column fixed="right" label="操作" min-width="120">
                    <template #default="{row}">
                        <el-button link type="primary" size="small" @click="editRow(row)">
                            评分
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
    </div>
  </div>

  <el-dialog
    v-model="dialogVisible"
    title="评分"
    width="500"
    :before-close="handleClose"
  >
    分数：<el-input v-model="ExamTitleStu.teacherPoint" style="width: 240px" placeholder="请输入分数" />
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="confirmPoint">
          确认
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>


<style lang="scss" scoped>
    .flex-row{
        display: flex;
        flex-direction: row;
    }
    .cus-header{
        .search{
            display: flex;
            flex-direction: row;
        }
    }
    .cus-body{
        margin-top: 15px;
    }
</style>